package com.audi.adapter;

import java.util.ArrayList;

import com.audi.R;
import com.audi.adapter.ListPlaceDialogAdapter.ViewHolder;
import com.audi.dto.PlaceItem;
import com.audi.utils.CapabilityHelper;
import com.audi.utils.Constants.PLACE_CAPABILITY;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MoveToDeviceDialogAdapter extends BaseAdapter {
    private ArrayList<PlaceItem> mPlaceItem;
    private Activity mActivity;

    public MoveToDeviceDialogAdapter(Activity activity,
	    ArrayList<PlaceItem> mPlaceItem) {
	mActivity = activity;
	this.mPlaceItem = mPlaceItem;
    }

    @Override
    public int getCount() {
	// TODO Auto-generated method stub
	return mPlaceItem.size();
    }

    @Override
    public Object getItem(int position) {
	// TODO Auto-generated method stub
	return mPlaceItem.get(position);
    }

    @Override
    public long getItemId(int position) {
	// TODO Auto-generated method stub
	return position;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup viewgroup) {
	// TODO Auto-generated method stub
	PlaceItem item = mPlaceItem.get(position);
	ViewHolder viewholder = null;
	if (convertview == null) {
	    viewholder = new ViewHolder();
	    convertview = LayoutInflater.from(mActivity).inflate(
		    R.layout.row_move_to_device_dialog, null);
	    viewholder.placeName = (TextView) convertview
		    .findViewById(R.id.txt_place_name_move_to);
	    viewholder.numDevice = (TextView) convertview
		    .findViewById(R.id.txt_place_count_move_to);
	    viewholder.statusPlace = (TextView) convertview
		    .findViewById(R.id.txt_place_status_move_to);
	    convertview.setTag(viewholder);
	} else {
	    viewholder = (ViewHolder) convertview.getTag();
	}
        viewholder.placeName.setText((CharSequence)item.getPlaceName());
        viewholder.numDevice.setText("("+item.getDeviceNumber()+")");
        viewholder.statusPlace.setText(CapabilityHelper.getCapabilityString(mActivity, item.getCapabilityType()));
	return convertview;
    }

    static class ViewHolder {
	private TextView placeName;
	private TextView numDevice;
	private TextView statusPlace;

    }

}
